From: tsteven4 Date: Mon, 11 Mar 2019 23:50:27 +0000 (-0600) Subject: replace random queues with QLists. (#323) X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~8^2~21 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22Program/%22http:/www.example.com/cgi/%22https:/%22Program?a=commitdiff_plain;h=c25b8ef3f50fd761cbcc986691f238e4623256d5;p=gpsbabel.git replace random queues with QLists. (#323) --- diff --git a/defs.h b/defs.h index fa742160f..d2fb72bb2 100644 --- a/defs.h +++ b/defs.h @@ -35,6 +35,7 @@ #include "session.h" #include +#include #include #include "src/core/datetime.h" #include "src/core/optional.h" diff --git a/garmin_gpi.cc b/garmin_gpi.cc index 2a8c4d4ad..6e4acfccd 100644 --- a/garmin_gpi.cc +++ b/garmin_gpi.cc @@ -44,14 +44,27 @@ * support category from GMSD "Garmin Special Data" */ +#include // for stable_sort +#include // for tolower +#include // for NULL, SEEK_CUR, SEEK_SET +#include // for atoi +#include +#include // for strcmp, strlen, strncmp, strncpy +#include // for time, gmtime + +#include // for QList<>::iterator, QList +#include // for QString, operator+, operator< +#include // for QThread +#include // for CaseInsensitive +#include // for foreach, Q_UNUSED + #include "defs.h" -#include "cet_util.h" -#include "garmin_fs.h" #include "garmin_gpi.h" -#include "jeeps/gpsmath.h" -#include -#include -#include +#include "cet_util.h" // for cet_convert_init +#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_flags_t, GMSD_SET, GMSD_GET, garmin_fs_alloc, GMSD_FIND +#include "gbfile.h" // for gbfputint32, gbfgetint32, gbfgetint16, gbfputint16, gbfgetc, gbfputc, gbfread, gbftell, gbfwrite, gbfseek, gbfclose, gbfile, gbfopen_le, gbsize_t, gbfgetuint16 +#include "jeeps/gpsmath.h" // for GPS_Math_Deg_To_Semi, GPS_Math_Semi_To_Deg + #define MYNAME "garmin_gpi" @@ -146,17 +159,16 @@ public: QString category; } reader_data_t; -typedef struct writer_data_s { - queue Q; - int ct; - int sz; - int alert; +struct writer_data_t { + QList waypt_list; + int sz{0}; + int alert{0}; bounds bds; - struct writer_data_s* top_left; - struct writer_data_s* top_right; - struct writer_data_s* buttom_left; - struct writer_data_s* buttom_right; -} writer_data_t; + writer_data_t* top_left{nullptr}; + writer_data_t* top_right{nullptr}; + writer_data_t* buttom_left{nullptr}; + writer_data_t* buttom_right{nullptr}; +}; typedef struct gpi_waypt_data_s { int sz; @@ -764,12 +776,10 @@ write_string(const char* str, const char long_format) gbfwrite(str, 1, len, fout); } -static int -compare_wpt_cb(const queue* a, const queue* b) +static bool +compare_wpt_cb(const Waypoint* a, const Waypoint* b) { - const Waypoint* wa = reinterpret_cast(a); - const Waypoint* wb = reinterpret_cast(b); - return wa->shortname.compare(wb->shortname); + return a->shortname < b->shortname; } static char @@ -781,8 +791,7 @@ compare_strings(const QString& s1, const QString& s2) static writer_data_t* wdata_alloc() { - writer_data_t* res = (writer_data_t*) xcalloc(1, sizeof(*res)); - QUEUE_INIT(&res->Q); + auto res = new writer_data_t; waypt_init_bounds(&res->bds); return res; @@ -792,10 +801,7 @@ wdata_alloc() static void wdata_free(writer_data_t* data) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(&data->Q, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, data->waypt_list) { if (wpt->extra_data) { gpi_waypt_t* dt = (gpi_waypt_t*) wpt->extra_data; @@ -820,15 +826,14 @@ wdata_free(writer_data_t* data) wdata_free(data->buttom_right); } - xfree(data); + delete data; } static void wdata_add_wpt(writer_data_t* data, Waypoint* wpt) { - data->ct++; - ENQUEUE_TAIL(&data->Q, &wpt->Q); + data->waypt_list.append(wpt); waypt_add_to_bounds(&data->bds, wpt); } @@ -836,15 +841,14 @@ wdata_add_wpt(writer_data_t* data, Waypoint* wpt) static void wdata_check(writer_data_t* data) { - queue* elem, *tmp; double center_lon; - if ((data->ct <= WAYPOINTS_PER_BLOCK) || + if ((data->waypt_list.size() <= WAYPOINTS_PER_BLOCK) || /* avoid endless loop for points (more than WAYPOINTS_PER_BLOCK) at same coordinates */ ((data->bds.min_lat >= data->bds.max_lat) && (data->bds.min_lon >= data->bds.max_lon))) { - if (data->ct > 1) { - sortqueue(&data->Q, compare_wpt_cb); + if (data->waypt_list.size() > 1) { + std::stable_sort(data->waypt_list.begin(), data->waypt_list.end(), compare_wpt_cb); } return; } @@ -852,16 +856,15 @@ wdata_check(writer_data_t* data) /* compute the (mean) center of current bounds */ double center_lat = center_lon = 0; - QUEUE_FOR_EACH(&data->Q, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, data->waypt_list) { center_lat += wpt->latitude; center_lon += wpt->longitude; } - center_lat /= data->ct; - center_lon /= data->ct; + center_lat /= data->waypt_list.size(); + center_lon /= data->waypt_list.size(); - QUEUE_FOR_EACH(&data->Q, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + while (!data->waypt_list.isEmpty()) { + Waypoint* wpt = data->waypt_list.takeFirst(); writer_data_t** ref; if (wpt->latitude < center_lat) { @@ -882,9 +885,6 @@ wdata_check(writer_data_t* data) *ref = wdata_alloc(); } - data->ct--; - dequeue(&wpt->Q); - wdata_add_wpt(*ref, wpt); } @@ -906,17 +906,15 @@ wdata_check(writer_data_t* data) static int wdata_compute_size(writer_data_t* data) { - queue* elem, *tmp; int res = 0; - if (QUEUE_EMPTY(&data->Q)) { + if (data->waypt_list.isEmpty()) { goto skip_empty_block; /* do not issue an empty block */ } res = 23; /* bounds, ... of tag 0x80008 */ - QUEUE_FOR_EACH(&data->Q, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, data->waypt_list) { garmin_fs_t* gmsd; res += 12; /* tag/sz/sub-sz */ @@ -1050,7 +1048,7 @@ skip_empty_block: data->sz = res; - if (QUEUE_EMPTY(&data->Q)) { + if (data->waypt_list.isEmpty()) { return res; } @@ -1061,9 +1059,7 @@ skip_empty_block: static void wdata_write(const writer_data_t* data) { - queue* elem, *tmp; - - if (QUEUE_EMPTY(&data->Q)) { + if (data->waypt_list.isEmpty()) { goto skip_empty_block; /* do not issue an empty block */ } @@ -1080,9 +1076,8 @@ wdata_write(const writer_data_t* data) gbfputint16(1, fout); gbfputc(data->alert, fout); - QUEUE_FOR_EACH(&data->Q, elem, tmp) { + foreach (const Waypoint* wpt, data->waypt_list) { int s1; - Waypoint* wpt = reinterpret_cast(elem); gpi_waypt_t* dt = (gpi_waypt_t*) wpt->extra_data; QString str = wpt->description; @@ -1266,10 +1261,7 @@ write_header() static void enum_waypt_cb(const Waypoint* ref) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(&wdata->Q, elem, tmp) { - Waypoint* cmp = reinterpret_cast(elem); + foreach (const Waypoint* cmp, wdata->waypt_list) { /* sort out nearly equal waypoints */ if ((compare_strings(cmp->shortname, ref->shortname) == 0) && diff --git a/gdb.cc b/gdb.cc index 41de965fc..6b9bc0090 100644 --- a/gdb.cc +++ b/gdb.cc @@ -21,16 +21,29 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#include // for fabs +#include // for printf, snprintf, sscanf, SEEK_SET, NULL +#include // for atoi, strtol, NULL +#include // for memset, strcmp, strstr, strchr, strlen, strncpy +#include // for strftime + +#include // for QByteArray +#include // for QList +#include // for QString, operator!=, operator== +#include // for CaseInsensitive +#include // for qPrintable, Q_UNUSED, foreach + #include "defs.h" -#include "cet_util.h" -#include "csv_util.h" -#include "garmin_fs.h" -#include "garmin_tables.h" -#include "grtcirc.h" -#include "jeeps/gpsmath.h" -#include -#include +#include "cet_util.h" // for cet_convert_init +#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_flags_t, garmin_ilink_t, GMSD_GET, GMSD_SETSTR, GMSD_SET, garmin_fs_alloc, GMSD_FIND, GMSD_HAS +#include "garmin_tables.h" // for gt_get_icao_country, gt_waypt_class_map_point, gt_color_index_by_rgb, gt_color_value, gt_waypt_classes_e, gt_find_desc_from_icon_number, gt_find_icon_number_from_desc, gt_gdb_display_mode_symbol, gt_waypt_class_user_waypoint, GDB, gt_display_mode_symbol +#include "gbfile.h" // for gbfputint32, gbfgetint32, gbfread, gbfwrite, gbfgetc, gbfputc, gbfgetdbl, gbfgetcstr, gbfile, gbfclose, gbfputcstr, gbfcopyfrom, gbfrewind, gbfseek, gbftell, gbfopen_le, gbfgetcstr_old, gbfgetint16, gbfputdbl, gbfputint16 +#include "grtcirc.h" // for RAD, gcdist, radtometers +#include "jeeps/gpsmath.h" // for GPS_Math_Deg_To_Semi, GPS_Math_Semi_To_Deg +#include "queue.h" // for queue, QUEUE_FOR_EACH +#include "src/core/datetime.h" // for DateTime + #define MYNAME "gdb" @@ -70,7 +83,7 @@ static char gdb_release_date[] = "$Date: 2011-04-14 01:30:01 $"; static gbfile* fin, *fout, *ftmp; static int gdb_ver, gdb_category, gdb_via, gdb_roadbook; -static queue wayptq_in, wayptq_out, wayptq_in_hidden; +static QList wayptq_in, wayptq_out, wayptq_in_hidden; static short_handle short_h; static char* gdb_opt_category; @@ -95,13 +108,11 @@ static int trk_ct; /* informational: total number of tracks in/out */ #define NOT_EMPTY(a) (a && *a) static void -gdb_flush_waypt_queue(queue* Q) +gdb_flush_waypt_queue(QList* Q) { - queue* elem, *tmp; - QUEUE_FOR_EACH(Q, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); - dequeue(elem); + while(!Q->isEmpty()) { + const Waypoint* wpt = Q->takeFirst(); if (wpt->extra_data) { #if NEW_STRINGS // FIXME @@ -118,7 +129,6 @@ gdb_flush_waypt_queue(queue* Q) } } - #if GDB_DEBUG static void disp_summary(const gbfile* f) @@ -283,13 +293,10 @@ gdb_fread_strlist() } static Waypoint* -gdb_find_wayptq(const queue* Q, const Waypoint* wpt, const char exact) +gdb_find_wayptq(const QList* Q, const Waypoint* wpt, const char exact) { - queue* elem, *tmp; QString name = wpt->shortname; - - QUEUE_FOR_EACH(Q, elem, tmp) { - Waypoint* tmp = reinterpret_cast(elem); + foreach (Waypoint* tmp, *Q) { if (name.compare(tmp->shortname,Qt::CaseInsensitive) == 0) { if (! exact) { return tmp; @@ -996,8 +1003,8 @@ gdb_rd_init(const QString& fname) cet_convert_init(CET_CHARSET_UTF8, 1); } - QUEUE_INIT(&wayptq_in); - QUEUE_INIT(&wayptq_in_hidden); + wayptq_in.clear(); + wayptq_in_hidden.clear(); gdb_via = (gdb_opt_via && *gdb_opt_via) ? atoi(gdb_opt_via) : 0; gdb_roadbook = (gdb_opt_roadbook && *gdb_opt_roadbook) ? atoi(gdb_opt_roadbook) : 0; @@ -1059,9 +1066,9 @@ read_data() if ((gdb_via == 0) || (wpt_class == 0)) { waypt_add(wpt); Waypoint* dupe = new Waypoint(*wpt); - ENQUEUE_TAIL(&wayptq_in, &dupe->Q); + wayptq_in.append(dupe); } else { - ENQUEUE_TAIL(&wayptq_in_hidden, &wpt->Q); + wayptq_in_hidden.append(wpt); } break; case 'R': @@ -1630,7 +1637,7 @@ write_waypoint_cb(const Waypoint* refpt) Waypoint* wpt = new Waypoint(*refpt); gdb_check_waypt(wpt); - ENQUEUE_TAIL(&wayptq_out, &wpt->Q); + wayptq_out.append(wpt); gbfile* fsave = fout; fout = ftmp; @@ -1770,7 +1777,7 @@ gdb_wr_init(const QString& fname) cet_convert_init(CET_CHARSET_UTF8, 1); } - QUEUE_INIT(&wayptq_out); + wayptq_out.clear(); short_h = nullptr; waypt_ct = 0; diff --git a/magproto.cc b/magproto.cc index 07bb385d3..58f1045e4 100644 --- a/magproto.cc +++ b/magproto.cc @@ -20,19 +20,36 @@ */ -#include "defs.h" -#include "explorist_ini.h" -#include "gbser.h" -#include "magellan.h" +#include "defs.h" // might include config.h, which might define HAVE_GLOB. + +#include // for isprint, toupper +#include // for fabs, lround +#include // for sprintf, sscanf, snprintf, size_t +#include // for atoi, atof, strtoul +#include // for strchr, strncmp, strlen, memmove, strrchr, memset +#include // for gmtime #if HAVE_GLOB #include #endif -#include -#include -#include -#include -#include + +#include // for QByteArray +#include // for QCharRef +#include // for QFileInfo +#include // for QLatin1String +#include // for QList +#include // for QString, operator== +#include // for QTime +#include // for CaseInsensitive +#include // for qPrintable, foreach + +#include "explorist_ini.h" // for explorist_ini_done, explorist_ini_get, mag_info +#include "gbfile.h" // for gbfclose, gbfeof, gbfgets, gbfopen, gbfwrite, gbfile +#include "gbser.h" // for gbser_deinit, gbser_init, gbser_is_serial, gbser_read_line, gbser_set_port, gbser_write, gbser_OK +#include "magellan.h" // for mm_meridian, mm_sportrak, icon_mapping_t, mm_gps315320, mm_unknown, mm_map330, mm_map410, pid_to_model_t, mm_gps310, m330_cleanse, mag_checksum, mag_find_descr_from_token, mag_find_token_from_descr, mag_rteparse, mag_trkparse +#include "queue.h" // for queue, QUEUE_FOR_EACH +#include "src/core/datetime.h" // for DateTime + static int bitrate = 4800; static int wptcmtcnt; @@ -85,12 +102,7 @@ typedef enum { /* * An individual element of a route. */ -class mag_rte_elem { - public: - mag_rte_elem() { - QUEUE_INIT(&Q); - } - queue Q; /* My link pointers */ +struct mag_rte_elem { QString wpt_name; QString wpt_icon; }; @@ -98,13 +110,13 @@ class mag_rte_elem { /* * A header of a route. Related elements of a route belong to this. */ -typedef struct mag_rte_head_ { - queue Q; /* Queue head for child rte_elems */ - char* rte_name; - int nelems; -} mag_rte_head; +struct mag_rte_head_t { + QList elem_list; /* list of child rte_elems */ + char* rte_name{nullptr}; + int nelems{0}; +}; -static queue rte_wpt_tmp; /* temporary PGMNWPL msgs for routes */ +static QList rte_wpt_tmp; /* temporary PGMNWPL msgs for routes */ static gbfile* magfile_h; static mag_rxstate magrxstate; @@ -496,7 +508,7 @@ retry: if (extension_hint == WPTDATAMASK) { waypt_add(wpt); } else if (extension_hint == RTEDATAMASK) { - ENQUEUE_TAIL(&rte_wpt_tmp, &wpt->Q); + rte_wpt_tmp.append(wpt); } } else { switch (objective) { @@ -504,7 +516,7 @@ retry: waypt_add(wpt); break; case rtedata: - ENQUEUE_TAIL(&rte_wpt_tmp, &wpt->Q); + rte_wpt_tmp.append(wpt); break; default: break; @@ -793,7 +805,7 @@ mag_rd_init_common(const QString& portname) terminit(portname, 0); mag_serial_init_common(portname); - QUEUE_INIT(&rte_wpt_tmp); + rte_wpt_tmp.clear(); /* find the location of the tail of the path name, * make a copy of it, then lop off the file extension @@ -860,7 +872,7 @@ mag_wr_init_common(const QString& portname) terminit(portname, 1); mag_serial_init_common(portname); - QUEUE_INIT(&rte_wpt_tmp); + rte_wpt_tmp.clear(); } /* @@ -903,7 +915,9 @@ mag_deinit() mkshort_del_handle(&mkshort_handle); } - waypt_flush(&rte_wpt_tmp); + while (!rte_wpt_tmp.isEmpty()) { + delete rte_wpt_tmp.takeFirst(); + } trk_head = nullptr; @@ -1025,7 +1039,7 @@ mag_rteparse(char* rtemsg) int frags,frag,rtenum; char xbuf[100],next_stop[100],abuf[100]; char* currtemsg; - static mag_rte_head* mag_rte_head; + static mag_rte_head_t* mag_rte_head; char* p; #if 0 @@ -1062,8 +1076,7 @@ mag_rteparse(char* rtemsg) * queue head. */ if (frag == 1) { - mag_rte_head = (struct mag_rte_head_*) xcalloc(sizeof(*mag_rte_head),1); - QUEUE_INIT(&mag_rte_head->Q); + mag_rte_head = new mag_rte_head_t; mag_rte_head->nelems = frags; } @@ -1088,7 +1101,7 @@ mag_rteparse(char* rtemsg) rte_elem->wpt_name = next_stop; rte_elem->wpt_icon = abuf; - ENQUEUE_TAIL(&mag_rte_head->Q, &rte_elem->Q); + mag_rte_head->elem_list.append(rte_elem); /* Sportrak (the non-mapping unit) creates malformed * RTE sentence with no icon info after the routepoint @@ -1099,7 +1112,7 @@ mag_rteparse(char* rtemsg) rte_elem = new mag_rte_elem; rte_elem->wpt_name = abuf; - ENQUEUE_TAIL(&mag_rte_head->Q, &rte_elem->Q); + mag_rte_head->elem_list.append(rte_elem); } next_stop[0] = 0; @@ -1111,7 +1124,6 @@ mag_rteparse(char* rtemsg) * gpsbabel internal structs now. */ if (frag == mag_rte_head->nelems) { - queue* elem, *tmp; route_head* rte_head = route_head_alloc(); route_add_head(rte_head); @@ -1124,15 +1136,13 @@ mag_rteparse(char* rtemsg) * those in the queue for SD routes... */ - QUEUE_FOR_EACH(&mag_rte_head->Q, elem, tmp) { - mag_rte_elem* re = reinterpret_cast(elem); - queue* welem, *wtmp; + while (!mag_rte_head->elem_list.isEmpty()) { + mag_rte_elem* re = mag_rte_head->elem_list.takeFirst(); /* * Copy route points from temp wpt queue. */ - QUEUE_FOR_EACH(&rte_wpt_tmp, welem, wtmp) { - Waypoint* waypt = reinterpret_cast(welem); + foreach (const Waypoint* waypt, rte_wpt_tmp) { if (waypt->shortname == re->wpt_name) { Waypoint* wpt = new Waypoint(*waypt); route_add_wpt(rte_head, wpt); @@ -1140,10 +1150,9 @@ mag_rteparse(char* rtemsg) } } - dequeue(&re->Q); delete re; } - xfree(mag_rte_head); + delete mag_rte_head; } } diff --git a/mapsource.cc b/mapsource.cc index ab7db4faf..17cbcd58f 100644 --- a/mapsource.cc +++ b/mapsource.cc @@ -21,12 +21,23 @@ /* #define MPS_DEBUG 0 */ +#include // for SEEK_CUR, sprintf, SEEK_SET, EOF, size_t +#include // for atoi, rand, srand +#include // for strcpy, memset, strlen, strcmp +#include // for time_t + +#include // for QChar +#include // for QFile +#include // for QList +#include // for QString, operator== + #include "defs.h" -#include "garmin_tables.h" -#include "jeeps/gpsmath.h" -#include -#include -#include +#include "garmin_tables.h" // for gt_find_icon_number_from_desc, MAPSOURCE, gt_find_desc_from_icon_number, GARMIN_SERIAL, PCX, garmin_formats_e +#include "gbfile.h" // for gbfwrite, gbfread, gbfgetint32, gbfputint32, gbfseek, gbfputc, gbfgetc, gbfputdbl, gbfgetdbl, gbfclose, gbfeof, gbfile, gbftell, gbfgetcstr, gbfputs, gbfopen_le +#include "jeeps/gpsmath.h" // for GPS_Math_Deg_To_Semi, GPS_Math_Semi_To_Deg +#include "queue.h" // for queue, QUEUE_FOR_EACH +#include "src/core/datetime.h" // for DateTime + static gbfile* mps_file_in; static gbfile* mps_file_out; @@ -43,12 +54,12 @@ static QString fin_name; static const Waypoint* prevRouteWpt; /* Private queues of written out waypoints */ -static queue written_wpt_head; -static queue written_route_wpt_head; +static QList written_wpt_head; +static QList written_route_wpt_head; static short_handle written_wpt_mkshort_handle; /* Private queue of read in waypoints assumed to be used only for routes */ -static queue read_route_wpt_head; +static QList read_route_wpt_head; static short_handle read_route_wpt_mkshort_handle; #define MPSDEFAULTWPTCLASS 0 @@ -113,19 +124,16 @@ mps_noop(const route_head*) } static void -mps_wpt_q_init(queue* whichQueue) +mps_wpt_q_init(QList* whichQueue) { - QUEUE_INIT(whichQueue); + whichQueue->clear(); } static void -mps_wpt_q_deinit(queue* whichQueue) +mps_wpt_q_deinit(QList* whichQueue) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(whichQueue, elem, tmp) { - Waypoint* q = reinterpret_cast(dequeue(elem)); - delete q; + while (!whichQueue->isEmpty()) { + delete whichQueue->takeFirst(); } } @@ -134,12 +142,9 @@ mps_wpt_q_deinit(queue* whichQueue) * */ static Waypoint* -mps_find_wpt_q_by_name(const queue* whichQueue, const QString& name) +mps_find_wpt_q_by_name(const QList* whichQueue, const QString& name) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(whichQueue, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); + foreach (Waypoint* waypointp, *whichQueue) { if (waypointp->shortname == name) { return waypointp; } @@ -152,10 +157,10 @@ mps_find_wpt_q_by_name(const queue* whichQueue, const QString& name) * */ static void -mps_wpt_q_add(const queue* whichQueue, const Waypoint* wpt) +mps_wpt_q_add(QList* whichQueue, const Waypoint* wpt) { Waypoint* written_wpt = new Waypoint(*wpt); - ENQUEUE_TAIL(whichQueue, &written_wpt->Q); + whichQueue->append(written_wpt); } static int diff --git a/nmea.cc b/nmea.cc index 00b26e63c..5d4e3919b 100644 --- a/nmea.cc +++ b/nmea.cc @@ -20,22 +20,34 @@ */ +#include // for isprint +#include // for fabs, lround +#include // for snprintf, sscanf, NULL, fprintf, fputc, stderr +#include // for atoi, atof +#include // for strncmp, memset, strlen, strchr, strstr, strrchr +#include // for gmtime + +#include // for QByteArray +#include // for QChar, operator==, operator!= +#include // for QCharRef +#include // for QDateTime +#include // for QList +#include // for QString, QString::KeepEmptyParts +#include // for QStringList +#include // for QThread +#include // for QTime +#include // for qPrintable #include "defs.h" -#include "cet_util.h" -#include "gbser.h" -#include "jeeps/gpsmath.h" -#include "src/core/logging.h" -#include "strptime.h" +#include "cet_util.h" // for cet_convert_init +#include "gbfile.h" // for gbfprintf, gbfflush, gbfclose, gbfopen, gbfgetstr, gbfile +#include "gbser.h" // for gbser_set_speed, gbser_flush, gbser_read_line, gbser_deinit, gbser_init, gbser_write +#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M +#include "queue.h" // for queue, QUEUE_FOR_EACH, QUEUE_LAST +#include "src/core/datetime.h" // for DateTime +#include "src/core/logging.h" // for Warning +#include "strptime.h" // for strptime -#include -#include -#include -#include -#include - -#include -#include /********************************************************** @@ -165,7 +177,7 @@ static Waypoint* curr_waypt; static Waypoint* last_waypt; static void* gbser_handle; static QString posn_fname; -static queue pcmpt_head; +static QList pcmpt_head; static int without_date; /* number of created trackpoints without a valid date */ static struct tm opt_tm; /* converted "date" parameter */ @@ -277,7 +289,7 @@ nmea_rd_init(const QString& fname) CHECK_BOOL(opt_gpgsa); CHECK_BOOL(opt_gisteq); - QUEUE_INIT(&pcmpt_head); + pcmpt_head.clear(); if (getposnarg) { getposn = 1; @@ -826,11 +838,10 @@ pcmpt_parse(char* ibuf) dmy = dmy / 100; tm.tm_mday = dmy; nmea_set_waypoint_time(curr_waypt, &tm, 0); - ENQUEUE_HEAD(&pcmpt_head, &curr_waypt->Q); + pcmpt_head.prepend(curr_waypt); } else { - queue* elem, *tmp; - if (QUEUE_EMPTY(&pcmpt_head)) { + if (pcmpt_head.isEmpty()) { return; } @@ -841,8 +852,8 @@ pcmpt_parse(char* ibuf) */ route_head* trk_head = route_head_alloc(); track_add_head(trk_head); - QUEUE_FOR_EACH(&pcmpt_head, elem, tmp) { - Waypoint* wpt = reinterpret_cast(dequeue(elem)); + while (!pcmpt_head.isEmpty()) { + Waypoint* wpt = pcmpt_head.takeFirst(); nmea_add_wpt(wpt, trk_head); } } diff --git a/radius.cc b/radius.cc index d4f2c996d..0a68b49c5 100644 --- a/radius.cc +++ b/radius.cc @@ -61,7 +61,6 @@ void RadiusFilter::process() #endif Waypoint** comp; int i, wc; - queue temp_head; route_head* rte_head = nullptr; #if NEWQ foreach (Waypoint* waypointp, waypt_list) { @@ -89,7 +88,6 @@ void RadiusFilter::process() } wc = waypt_count(); - QUEUE_INIT(&temp_head); comp = (Waypoint**) xcalloc(wc, sizeof(*comp)); diff --git a/stmsdf.cc b/stmsdf.cc index f97c28d0e..78b096d3f 100644 --- a/stmsdf.cc +++ b/stmsdf.cc @@ -20,7 +20,7 @@ */ /* - 2006/04/05: initial release (not published in GPSBbabel) + 2006/04/05: initial release (not published in GPSBabel) 2006/07/19: finished reader and writer for type 4,5,28 of ver. 1 2006/10/31: remove wptdata from case statement (data_write) @@ -31,16 +31,28 @@ #if CSVFMTS_ENABLED -#include "cet_util.h" -#include "csv_util.h" -#include "jeeps/gpsmath.h" -#include "grtcirc.h" -#include "src/core/logging.h" +#include // for sort +#include // for atoi +#include // for strchr +#include // for localtime, strftime + +#include // for QDate +#include // for QDateTime +#include // for QList<>::iterator, QList +#include // for QRegularExpression +#include // for QString, operator+, QString::KeepEmptyParts +#include // for QStringList +#include // for QTime +#include // for qAsConst, QAddConst<>::Type + +#include "cet_util.h" // for cet_convert_init +#include "csv_util.h" // for csv_lineparse +#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfgetstr, gbfile +#include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers +#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_WGS84_To_Known_Datum_M +#include "src/core/datetime.h" // for DateTime +#include "src/core/logging.h" // for Warning, Fatal -#include -#include -#include -#include #define MYNAME "stmsdf" @@ -59,7 +71,7 @@ static int lineno; static int datum; static int filetype; static route_head* route; -static queue trackpts; +static QList trackpts; static QString rte_name; static QString rte_desc; @@ -76,7 +88,7 @@ static int all_points; static int this_points; static int saved_points; static time_t start_time; -static unsigned char this_valid; +static bool this_valid; static short_handle short_h; #define route_index this_index @@ -169,43 +181,25 @@ parse_header(char* line) } } -static int -track_qsort_cb(const void* a, const void* b) +static bool +track_sort_cb(const Waypoint* a, const Waypoint* b) { - const Waypoint* wa = *(Waypoint**)a; - const Waypoint* wb = *(Waypoint**)b; - - return wa->GetCreationTime().toTime_t() - wb->GetCreationTime().toTime_t(); + return a->GetCreationTime() < b->GetCreationTime(); } static void finalize_tracks() { - queue* elem, *tmp; route_head* track = nullptr; int trackno = 0; - int count = 0; - QUEUE_FOR_EACH(&trackpts, elem, tmp) { - count++; - }; - if (count == 0) { + if (trackpts.isEmpty()) { return; } - Waypoint** list = (Waypoint**)xmalloc(count * sizeof(*list)); - - int index = 0; - QUEUE_FOR_EACH(&trackpts, elem, tmp) { - list[index] = reinterpret_cast(elem); - dequeue(elem); - index++; - } - - qsort(list, count, sizeof(*list), track_qsort_cb); + std::sort(trackpts.begin(), trackpts.end(), track_sort_cb); - for (index = 0; index < count; index++) { - Waypoint* wpt = list[index]; + foreach (Waypoint* wpt, trackpts) { if (wpt->wpt_flags.fmt_use == 2) { /* log continued */ track = nullptr; } @@ -231,7 +225,7 @@ finalize_tracks() wpt->wpt_flags.fmt_use = 0; } - xfree(list); + trackpts.clear(); } static void @@ -367,7 +361,7 @@ parse_point(char *line) { switch (what) { case 0: case 1: - ENQUEUE_TAIL(&trackpts, &wpt->Q); + trackpts.append(wpt); break; case 2: case 3: @@ -395,7 +389,7 @@ rd_init(const QString& fname) filetype = 28; rte_name = rte_desc = QString(); - QUEUE_INIT(&trackpts); + trackpts.clear(); } static void